package cn.simon.free.redis.jedis.common;

import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author simon
 * @date 2021/5/14 11:16
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
public abstract class AbstractJedis implements JedisCommon {

    @Resource
    protected RedisTemplate<String, String> redisTemplate;

    @Override
    public boolean setExpire(String key, long timeOut) {
        return redisTemplate.expire(key, timeOut, TimeUnit.SECONDS);
    }

    @Override
    public boolean setExpireAt(String key, Date timeOut) {
        return redisTemplate.expireAt(key, timeOut);
    }

    @Override
    public boolean del(String key) {
        return redisTemplate.delete(key);
    }

    @Override
    public boolean exists(String key) {
        return redisTemplate.hasKey(key);
    }

    @Override
    public Object type(String key) {
        return redisTemplate.type(key);
    }

    public boolean setExpire(String key, long timeOut, TimeUnit timeUnit) {
        return redisTemplate.expire(key, timeOut, timeUnit);
    }
}
